package org.atovio.coolexam.mapper;

import org.apache.ibatis.annotations.*;
import org.atovio.coolexam.common.Role;
import org.atovio.coolexam.entity.User;

import java.util.List;
import java.util.Map;

public interface UserMapper {

    @Insert("""
            insert into t_user(user_uuid, user_id, user_name, real_name, password, role, image_path,phone, `email`)
            VALUES (UUID(), #{userId}, #{userName}, #{realName},#{password}, #{role}, #{imagePath},#{phone},#{email})
            """)
    int insert(User user);

    @Select("select * from t_user;")
    List<User> selectAll();

    @Select("select * from t_user where user_id = #{userId}")
    User selectByUserId(Integer userId);

    @Select("select * from t_user where user_uuid = #{userUuid}")
    User selectByUserUuid(String userUuid);

    @Select("select * from t_user where user_id = #{userId} and password = #{password}")
    User selectByUserIdAndPassword(@Param("userId") Integer userId, @Param("password") String password);

    /**
     * 根据自定义条件查询
     *
     * @param criteria 自定义条件
     * @return 记录
     */
    List<User> selectSelective(@Param("criteria") Map<String, Object> criteria);

    /**
     * 根据自定义条件查询记录条数
     *
     * @param criteria 自定义条件
     * @return 记录条数
     */
    int selectCountSelective(@Param("criteria") Map<String, Object> criteria);

    @Delete("delete from t_user where user_uuid = #{UserUuid}")
    int deleteByUserUuid(String UserUuid);

    @Update("update t_user set email = #{email}, phone = #{phone}, user_name = #{userName}, real_name = #{realName} where user_uuid = #{userUuid};")
    int update(User user);

    @Update("update t_user set password = #{password} where user_uuid = #{userUuid}")
    int updatePasswordByUserUuid(String password, String userUuid);

    @Update("update t_user set user_name = #{username} where user_uuid = #{userUuid}")
    int updateUsernameByUserUuid(@Param("username") String username, @Param("userUuid") String userUuid);

    @Update("update t_user set real_name = #{realName} where user_uuid = #{userUuid}")
    int updateRealNameByUserUuid(String realName, String userUuid);

    @Update("update t_user set phone = #{phone} where user_uuid = #{userUuid}")
    int updatePhoneByUserUuid(String phone, String userUuid);

    @Update("update t_user set email = #{email} where user_uuid = #{userUuid}")
    int updateEmailByUserUuid(String email, String userUuid);

    @Update("update t_user set role = #{role} where user_uuid = #{userUuid}")
    int updateRoleByUserUuid(int role, String userUuid);

    @Update("update t_user set image_path = #{imagePath} where user_uuid = #{userUuid}")
    int updateImagePathByUserUuid(@Param("imagePath") String imagePath, @Param("userUuid") String userUuid);
}
